﻿using API_Service.BizLogic.SOPControl;
using Nancy;

namespace API_Service.Module
{
    public class ESOPServiceModule:BaseAPIModule
    {
        private ESOPService _esop = new ESOPService();        
        public ESOPServiceModule() : base("/esop")
        {
            Get["/"] = _ => Response.AsJson("ESOP管理.");
            //测试样例
            Get["/test"] = _ =>
            {
                return Response.AsJson(_esop.QuerySOPConfigInfo("GROUP1", "TEST_SKU"));
            };
            //查询SOP信息List信息
            Get["/getlist"] = _ =>
            {
                ExecutionResult<dynamic> result;
                var group = Request.Query.group;
                var sku = Request.Query.sku;

                result = _esop.QuerySOPConfigInfo(group, sku);

                return Response.AsJson(result);
            };
            //按站别+机种获取SOP信息
            Get["/getsop"] = _ =>
             {
                 ExecutionResult<dynamic> result;                 
                 var group = Request.Query.group;
                 var sku = Request.Query.sku;

                 result = _esop.GetSOPInfo(group, sku);

                 return Response.AsJson(result);
             };
            //添加ESOP基础信息
            Post["/add"] = _ =>
            {
                string model = Request.Form["MODEL"];
          
                return Response.AsJson(_esop.AddSOPBase(model));
            };
            //更新SOP信息
            Post["/update"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(_esop.UpdateSOPBase(model));
            };
            //删除SOP信息
            Post["/delete/{id}"] = p =>
             {
                 string _id = (string)p.id;

                 return Response.AsJson(_esop.DeleteSOPBase(_id));
             };
        }
    }
}